﻿using Microsoft.AspNetCore.Mvc;
using MinimalistFoodStreet.BackEnd.Infrastructure.Attributes;
using MinimalistFoodStreet.BackEnd.Infrastructure.Dtos.Request.Tables;
using MinimalistFoodStreet.BackEnd.Infrastructure.Dtos.Response;
using MinimalistFoodStreet.BackEnd.Server.IServer.Tables;

namespace MinimalistFoodStreet.BackEnd.Api.Api.Controllers.Tables
{
    [CheckLogin(new CheckLoginRoles[] { CheckLoginRoles.administrators })]
    public class BusinesssController : BaseController
    {
        private readonly IBusinesssServer _businessServer;

        public BusinesssController(IBusinesssServer businesssServer)
        {
            _businessServer = businesssServer;
        }
        /// <summary>
        /// 商户添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [ActionLog("商户添加")]
        [HttpPost]
        public async Task<IActionResult> AddAsync(RequestCreateBusinesssDto dto)
        {
            return Send(await _businessServer.AddAsync(dto));
        }
        /// <summary>
        /// 商户更新
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [ActionLog("商户更新")]
        [HttpPost]
        public async Task<IActionResult> UpdateAsync(RequestUpdateBusinesssDto dto)
        {
            return Send(await _businessServer.UpdateAsync(dto));
        }
        /// <summary>
        /// 商户删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [ActionLog("商户删除")]
        [HttpPost]
        public async Task<IActionResult> DeleteAsync(RequestDeleteBusinesssDto dto)
        {
            return Send(await _businessServer.DeleteAsync(dto));
        }
        /// <summary>
        /// 商户详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [ActionLog("商户详情")]
        [HttpGet]
        public async Task<IActionResult> DetailAsync(int id)
        {
            return Send(await _businessServer.DetailAsync(id));
        }
        /// <summary>
        /// 商户分页
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [ActionLog("商户分页")]
        [HttpGet]
        public async Task<IActionResult> PaginationAsync(int page, int limit, string? key)
        {
            return Send(await _businessServer.PaginationAsync(page, limit, key));
        }
    }
}
